<template>
  <div class="h5-wrapper">
    <router-view></router-view>
  </div>
</template>

<script>
import axios from 'axios';
axios.defaults.baseURL = 'http://123.57.109.30:3006';
// 下包  yarn  add  axios
// 请求地址: https://mock.boxuegu.com/mock/3083/articles
// 请求拦截器
axios.interceptors.request.use(
 (config) => {
  console.log(config);
  config.headers.token = "qweqwe";
  return config; //将操作后的请求数据 返回
 },
 (err) => {
  return Promise.reject(err);
 }
);
//响应拦截器
// axios.interceptors.request.use((response)=>{
//   console.log(response.data);
//   return response.data.data
// },function (err) {
//   return Promise.reject(err);
  
// })
// 响应拦截器
axios.interceptors.response.use((response) => {
console.log(response.data);
 return response.data.data.bookname
},function(error){
 return Promise.rejece(error)
})

// 请求方式: get
export default {
  name: 'h5-wrapper',
  // created () {
  //   axios({
  //     method:'get',
  //     url:" https://mock.boxuegu.com/mock/3083/articles"
  //   }).then(res=>{
  //     console.log(res);
  //   }).catch(e=>{
  //     console.log(e);
  //   })

  // }
  async created() {
    // try {
    //   const res = await axios({
    //     method: 'get',
    //     url: ' https://mock.boxuegu.com/mock/3083/articles',
    //   });
    //   console.log(res);
    // } catch (e) {
    //   console.log(e);
    // }
    // axios({
    //   params: {
    //     url: 'http://123.57.109.30:3006/api/getbooks',
    //     bookname: '西游记',
    //   },
    // }).then((res) => {
    //   console.log(res);
    //   // })
    try {
      await axios({
        url: '/api/addbook',
        method: 'post',
        data: {
          appkey: '7250d3eb-18e1-41bc-8bb2-11483665535a',
          bookname: '数目',
          author: '李娜',
          publisher: '出版方',
        },
      }).then((res) => {
        console.log(res);
      });
    } catch (err) {
      console.log(err);
    }
  },
  //   带参数的get
  // Url: http://123.57.109.30:3006/api/getbooks
  // Method: GET
  // 参数: bookname 书本名称
};
</script>

<style>
body {
  margin: 0;
  padding: 0;
}
</style>
<style lang="less" scoped>
.h5-wrapper {
  .content {
    margin-bottom: 51px;
  }
  .tabbar {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    display: flex;
    background: #fff;
    border-top: 1px solid #e4e4e4;
    a {
      flex: 1;
      text-decoration: none;
      font-size: 14px;
      color: #333;
      -webkit-tap-highlight-color: transparent;
      &.router-link-active {
        color: #fa0;
      }
    }
  }
}
</style>
